<?php
session_start();
include 'conn.php';
//global $conn;
$flag = 0;

?>
<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- <link rel="icon" href="./images/icon.ico"> -->
    <link rel="stylesheet" type="text/css" href="./css/general.css">
    <link rel="stylesheet" type="text/css" href="./css/index.css">
    <script type="text/javascript" src="./js/jquery.js"></script>
    <script type="text/javascript" src="./js/general.js"></script>
    <script type="text/javascript" src="./js/carousel.js"></script>
    <title>simple_shop_demo</title>
</head>
<body>
<!-- 顶部开始 -->


<!-- 头部开始 -->
<?php include 'header.php'; ?>

<!-- 头部结束 -->
<!-- 主体开始 -->
<div class="container w1100">
    <div class="module cut">
        <!-- 商品分类开始 -->
        <div class="catebar w210 fl">
        </div>
        <!-- 商品分类结束 -->
        <!-- 轮播图片广告开始 -->
        <!--        <div class="w640 fl cut" style="margin-left: 20%">-->
        <!--            <div class="carousel cut">-->
        <!--                <div class="carousel-imgs cut">-->
        <!--                    --><?php
        //                    $sql = "select * from adv";
        //                    $result = $conn->query($sql);
        //                    if ($result->num_rows > 0) {
        //                        $count = $result->num_rows;
        //                        while ($row = $result->fetch_assoc()) {
        //                            ?>
        <!--                            <a href="--><?php //echo $row['link'] ?><!--" style="display: block;">-->
        <!--                                <img src="-->
        <?php //echo $row['picture'] ?><!--" width="630" height="240" border="0">-->
        <!--                            </a>-->
        <!--                            --><?php
        //                        }
        //                        ?>
        <!---->
        <!--                        <ul class="carousel-tog">-->
        <!--                            --><?php
        //                            while ($count > 0) {
        //                                ?>
        <!--                                <li class="cur">--><?php //echo $count ?><!--</li>-->
        <!--                                --><?php
        //                                $count -= 1;
        //                            }
        //                            ?>
        <!---->
        <!--                        </ul>-->
        <!--                        --><?php
        //                    }
        //                    ?>
        <!---->
        <!--                </div>-->
        <!---->
        <!--            </div>-->
        <!--        </div>-->
        <!-- 轮播图片广告结束 -->

    </div>
    <!-- 新品上市开始 -->
    <div class="module mt30 cut">
        <!--        <div class="gli_t"><h2 class="fl">所有商品</h2></div>-->
        <div class="gli w1110">
            <ul style="margin-left: 10%">
                <?php
                $nowPage = isset($_GET['page']) ? $_GET['page'] : 1;
                $re = echoList($nowPage);
                function echoList($num)
                {
                    $num = ($num - 1) * 8;
                    $sql = "SELECT * FROM goods LIMIT " . $num . ",8";
                    global $conn;
                    $result = $conn->query($sql);
                    if ($result->num_rows > 0) {
                        // 输出每行数据
                        while ($row = $result->fetch_assoc()) {
                            echo <<<ETO
        <li>
            <div class="im"><a href="goods.php?id=$row[id]"><img src=" $row[picture]"></a></div>
            <h3><a href="goods.php?id=$row[id]>
                     $row[goods_name];
                </a></h3>
            <del><p class="price"><i>原价¥</i>
                    $row[old_price]
                </p></del>
            <p class="price"><i>现价¥</i>
                 $row[price]
            </p>
        </li>
ETO;
                        }
                    }

                    $num += 8;
                    $sql = "SELECT * FROM goods LIMIT " . $num . ",8";
                    if ($conn->query($sql)->num_rows == 0)
                        return false;
                    else
                        return true;
                }

                ?>
            </ul>
        </div>
    </div>
    <div class="fanye">
        <form id="pagef" action="">
            <input style="display: none" id="pageI" name="page">
            <ul>
                <li>
                    <button onclick="changePage(-1);" type="submit" id="syy"><strong>上一页</strong></button>
                </li>
<!--                <li>-->
<!--                    <button onclick="changePage(0)">首页</button>-->
<!--                </li>-->
                <li>
                    <button onclick="changePage(1)" type="submit" id="xyy"><strong>下一页</strong></button>
                </li>
            </ul>
        </form>
    </div>
    <script>
        var nowPage = <?php echo $nowPage?>;
        if (nowPage <= 1) {
            document.getElementById('syy').disabled = true;
            nowPage = 1;
        }
        function changePage(num) {
            nowPage += num;
            document.getElementById('pageI').value = nowPage;
            document.getElementById('pagef').sub;
        }
        <?php
        if (!$re) {
            echo "document.getElementById('xyy').disabled = true";
        }
        ?>
    </script>
    <?php include 'footer.php'; ?>
